package com.echat.messagesender.sender.config;

import com.echat.messagesender.sender.constant.Constants;
import com.echat.messagesender.sender.mapper.PlatformMapper;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created by chenmohan on 2018/09/07
 *
 * @description
 */
@Configuration
@Log4j2
public class CommonDataConfig {

    @Autowired
    PlatformMapper platformMapper;

    @PostConstruct
    public void initPlatformData(){
        Map<Long, String> map = platformMapper.selectAll()
                .parallelStream()
                .collect(Collectors.toMap(e -> e.getId(), e -> e.getPlatformName()));
        Constants.platformMap = map;
        log.info("初始化platform数据成功!");
    }
}
